package com.zsw.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.zsw.recongize.bean.Invoice;
import com.zsw.recongize.parse.PdfBoxParse;

@RestController
public class Controller {

	@RequestMapping(value = "/getInvoiceInfo",method = RequestMethod.POST)
	public Map<String, Object> getInvoiceInfo(
			@RequestParam(required = false)MultipartFile file_) {
		Invoice invoice = new Invoice();
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			PdfBoxParse.pase(invoice, file_.getInputStream(), null, null);
			map.put("fileName", file_.getOriginalFilename());
			map.put("fpdm", invoice.getCode());
			map.put("fphm", invoice.getNumber());
			map.put("fprq", invoice.getDate().replaceAll("[年月日\\s]", ""));
			map.put("fpje", invoice.getCheckCode().replaceAll("[\\s]", ""));
			map.put("success", true);
			return map;
		} catch (IOException e) {
			e.printStackTrace();
		}
		map.put("success", false);
		return map;
	}
	
}
